﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace Wydatki.Tools
{
    public static class WebTools
    {
        public static bool CheckConnection()
        {
            WebClient w = CreateWebClient();
            bool result = true;

            try
            {
                w.DownloadString("http://www.google.com");
            }
            catch (Exception ex)
            {
                ex.Log();
                result = false;
            }
            return result;
        }

        public static WebClient CreateWebClient()
        {
            WebClient w = new WebClient();
            if (w.Proxy != null)
            {
                w.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
                w.Credentials = CredentialCache.DefaultNetworkCredentials;
                w.UseDefaultCredentials = true;
            }
            return w;
        }
    }
}
